<?php
/**
 * Created by JetBrains PhpStorm.
 * User: khathirdstep1025
 * Date: 9/27/12
 * Time: 9:52 PM
 * To change this template use File | Settings | File Templates.
 */

class Cart extends CI_Controller{
    public function __construct(){
        parent::__construct();

        $config['base_url'] = base_url() . 'index.php/cart/page';
        $config['total_rows'] = $this->db->count_all('product');
        $config['per_page'] = 12;

        $config['full_tag_open'] = '<div class="pagination pagination-centered">  <ul>';
        $config['full_tag_close'] = '</ul></div>';

        $config['num_tag_open'] = '<li>';$config['num_tag_close'] = '</li>';

        $config['cur_tag_open'] = "<li class='active'><a href='#'>";
        $config['cur_tag_close'] = '</a></li>';

        $config['first_link'] = 'Đầu tiên';
        $config['last_link'] = 'Cuối cùng';

        $config['next_link'] = 'Tiếp »';
        $config['prev_link'] = 'Lùi «';

        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';

        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';

        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';

        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';

        $config['num_links'] = 3;

        $this->pagination->initialize($config);
    }

    public function index(){
//        $data['products1'] = $this->cart_model->retrieve_products(4, 0);
//        $data['products2'] = $this->cart_model->retrieve_products(4, 4);
//        $data['products3'] = $this->cart_model->retrieve_products(4, 8);
//        $data['content'] = 'cart/products';
//
//        $this->load->view('cart/index', $data);
    }

    public function add_cart_item(){
        if ($this->cart_model->validate_add_cart_item() == TRUE){
            if ($this->input->post('ajax') != '1'){
                redirect('');
                return;
            } else {
                echo 'true';
                return;
            }
        }
    }

    public function show_cart(){
        $this->load->view('cart/cart');
    }

    public function update_cart(){
        $this->cart_model->validate_update_cart();
        redirect('');
    }

    public function show_total_cart(){
        echo $this->cart_model->total_cart();
    }

    public function show_total_content_item(){
        echo count($this->cart->contents());
    }

    public function empty_cart(){
        $this->cart_model->empty_cart();
    }

    public function page($page = 0){
        $data['products1'] = $this->cart_model->retrieve_products(4, $page);
        $data['products2'] = $this->cart_model->retrieve_products(4, $page + 4);
        $data['products3'] = $this->cart_model->retrieve_products(4, $page + 8);
        $data['content'] = 'cart/products';

        $this->load->view('cart/index', $data);
    }

    public function get_store_qty($id){
        if ($this->cart_model->product_qty($id) == "HET_HANG"){
            echo 'het_hang';
        } else {
            echo 'con_hang';
        }
    }
}